<?php

namespace App\Http\Controllers;

use App\Http\Requests\OrderConfirmRequest;
use App\Services\PosApi\Order;
use D1M\Common\Helpers\Result;

class OrderController extends Controller
{
    public function confirm(OrderConfirmRequest $request, Order $service)
    {
        $params = $request->post('data');
        $params['refund_no'] = isset($params['refund_no']) ? $params['refund_no'] : '';
        if ($params['type'] == 2 && empty($params['refund_no'])) {
            return Result::fail('退款单号缺失！');
        }
        $res = $service->confirm($params['type'], $params['order_no'], $params['refund_no']);
        return empty($res['error']) ? Result::success() : Result::fail($res['message']);
    }
}